<template>
	<view class="page">
		<Header :title="'收货地址'"></Header>
		<view class="addressBox">
			<view class="address_item" @click="selectAdd(item)" v-for="(item,i) in list" :key="i">
				<view class="item_left">
					<view class="item_info">
						<text class="info_name">{{item.contact}}</text>
						<text class="info_phone">{{item.phone}}</text>
					</view>
					<view class="item_address">
						<text>{{item.address}}{{item.detail}}</text>
					</view>
				</view>
				<view class="item_right" v-if="item.defaultSetting==1">
					<u-icon name="checkbox-mark" color='#40AE36'></u-icon>
				</view>
			</view>
		

			<view class="emptyBox" v-if="list.length==0">
				<image class="emptyIcon" src="../../../static/empty.png" mode="widthFix"></image>
				<view class="emptyText">
					您还没有收货地址！
				</view>
			</view>
		</view>
		<view class="bottom_box">
			<view class="bottom_btn" @click="toGo">
				新增收货地址
			</view>
		</view>
		<view class="kongbai"></view>

	</view>
</template>

<script>
	import Header from '@/components/header/header.vue'
	export default {
		data() {
			return {
				select: 0,
				background: {
					backgroundColor: '#21B070',
				},
				list: [],
				cont: 2
			}
		},
		onLoad(e) {
			this.cont = e.cont
		},
		onShow() {
			this.cread()
		},
		components: {
			Header
		},
		methods: {

			toGo() {
				uni.navigateTo({
					url: '/pages/my/serve/addAddress'
				})
			},
			async cread() {
				let res = await this.$api.request('system/address/user/list', 'get', {})
				this.list = res.data.list
			},
			selectAdd(e) {
				if (this.cont == 1) {
					uni.navigateBack()
					uni.setStorageSync('shopaddress', JSON.stringify(e))
				} else {
					console.log(11)
					uni.navigateTo({
						url: '/pages/my/serve/addAddress?id=' + e.id
					})
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.page {
		background-color: #f5f5f5;
		height: calc(100vh - 200rpx);
		overflow: scroll;
	}

	.kongbai {
		background-color: #f5f5f5;
		position: fixed;
		bottom: 0;
		height: 200rpx;
		width: 100%;
		z-index: 200;
	}

	.emptyBox {
		width: 100%;
		height: 50vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.emptyText {
			font-size: 32rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.emptyIcon {
			width: 20%;

		}
	}

	.addressBox {
		display: flex;
		flex-direction: column;
		margin-top: 20rpx;

		.address_item {
			background-color: #fff;
			padding: 30rpx;
			margin: 0 30rpx 22rpx;
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.item_info {
				display: flex;
				align-items: center;
				line-height: 42rpx;

				.info_name {
					margin: 0 16rpx;
					color: #333333;
					font-size: 30rpx;
				}

				.info_phone {
					font-size: 30rpx;
					color: #262424;
				}
			}

			.item_address {
				margin-top: 10rpx;
				font-size: 26rpx;
				line-height: 34rpx;
				color: #666262;
				width: 80%;
			}

			.item_right {
				width: 70rpx;
				text-align: center;
			}
		}
	}

	.bottom_box {
		position: fixed;
		bottom: 80rpx;
		width: 100%;
		display: flex;
		z-index: 300;

		.bottom_btn {
			background: #D42A1B;
			font-size: 30rpx;
			line-height: 44rpx;
			padding: 20rpx 222rpx;
			margin: 0 auto;
			border-radius: 45rpx;
			color: #FFFFFF;
		}
	}
</style>